package com.ysd.twocrm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysd.twocrm.entity.Userchecks;
import com.ysd.twocrm.mapper.UserChecksMapper;
import com.ysd.twocrm.service.UserCheckService;
import com.ysd.twocrm.utils.LayuiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

@Service
public class UserCheckServiceImpl implements UserCheckService {
    @Autowired
    private UserChecksMapper userChecksMapper;

    @Override
    public LayuiUtils<Userchecks> USERCHECKS_LAYUI_UTILS(Integer page, Userchecks u) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        LayuiUtils<Userchecks> userchecksLayuiUtils=new LayuiUtils<Userchecks>();
        QueryWrapper<Userchecks> queryWrapper=new QueryWrapper<Userchecks>();
       if(u.getUserCheckName()!=null){
           queryWrapper.like("userCheckName",u.getUserCheckName());
       }
       if(u.getUserCheckInTime()!=null){
           queryWrapper.like("userCheckInTime",sdf.format(u.getUserCheckInTime()));
       }
       if(u.getUserCheckOutTime()!=null){
           queryWrapper.like("userCheckOutTime",sdf.format(u.getUserCheckOutTime()));
       }
        Page<Userchecks> userchecksPage=new Page<Userchecks>(page,10);
        Page<Userchecks> userchecksPage1 = userChecksMapper.selectPage(userchecksPage, queryWrapper);
        userchecksLayuiUtils.setData(userchecksPage1.getRecords());
        userchecksLayuiUtils.setCount(userchecksPage1.getTotal());

        return userchecksLayuiUtils;
    }
}
